import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { Cache } from "../../cache/Cache";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { EffectManager } from "../../manager/EffectManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GuideTipsManager } from "../../manager/GuideTipsManager";
import { GameManager } from "../../manager/GameManager";
import { GameController } from "../../mvc/GameController";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { TweenMax } from "../../../../com/greensock/TweenMax";
import { DisplayUtil } from "../../../common/DisplayUtil";
//class PetMenuPanel
    
    export  class PetMenuPanel /* flash.display.Sprite */
    {
        constructor(arg1: Object /* flash.display.DisplayObjectContainer */)
        {
            
            this._container = arg1;
            this.init();
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            return;
        }

        public showJuBtn(): void
        {
            if (!this._juBtn) 
            {
                this._juBtn = ObjCreate.createGLoadedButton(ResFileConst.PetMingJuhun, 5, 170, 44, 54, null);
                this._juBtn.name = "ju";
                this._juBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            }
            if (!this._menuSprite.contains(this._juBtn)) 
            {
                this._menuSprite.addChild(this._juBtn);
            }
            this._bg.height = 232;
            return;
        }

        public get bgHeight(): number
        {
            return this._bg.height;
        }

        /* internal  */init(): void
        {
            this._menuSprite = new Object /* flash.display.Sprite */();
            this._menuSprite.visible = false;
            this.addChild(this._menuSprite);
            this._bg = ObjCreate.createBitmap(ImagesConst.PetMenuBg, 0, 0, this._menuSprite);
            this._hireBtn = ObjCreate.createGLoadedButton(ResFileConst.PetHire, 5, 5, 44, 54, this._menuSprite);
            this._hireBtn.name = "hire";
            this._exploreBtn = ObjCreate.createGLoadedButton(ResFileConst.PetExplore, 5, 60, 44, 54, this._menuSprite);
            this._exploreBtn.name = "explore";
            this._forgeBtn = ObjCreate.createGLoadedButton(ResFileConst.PetForge, 5, 115, 44, 54, this._menuSprite);
            this._forgeBtn.name = "forge";
            if (Cache.instance.petMing.isOpenJu) 
            {
                this._juBtn = ObjCreate.createGLoadedButton(ResFileConst.PetMingJuhun, 5, 170, 44, 54, this._menuSprite);
                this._juBtn.name = "ju";
                this._juBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
                this._bg.height = 232;
            }
            else 
            {
                this._bg.height = 178;
            }
            this._hireBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._exploreBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._forgeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=(arg1.target as GLoadedButton).name;
            if (loc1 != "hire") 
            {
                if (loc1 != "explore") 
                {
                    if (loc1 != "forge") 
                    {
                        if (loc1 != "competition") 
                        {
                            if (loc1 == "ju") 
                            {
                                EffectManager.glowFilterUnReg(this._juBtn);
                                Dispatcher.dispatchEvent(new DataEvent(EventName.PetMingJuWindowOpen));
                            }
                        }
                        else 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.PetCpnOpenWindow));
                            if (Cache.instance.guide.petFightChange) 
                            {
                                Cache.instance.guide.petFightChange = false;
                                GuideTipsManager.hideGuideTips();
                                EffectManager.glowFilterUnReg(this._competitionBtn);
                            }
                        }
                    }
                    else 
                    {
                        if (Cache.instance.guide.petEquipRefresh || Cache.instance.guide.guidePetEquipStrenthenStep == 1) 
                        {
                            GuideTipsManager.hideGuideTips();
                            EffectManager.glowFilterUnReg(this._forgeBtn);
                        }
                        GameManager.instance.popupView(GameController.petEquip.view);
                    }
                }
                else 
                {
                    if (Cache.instance.role.entityInfo.level < 50) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(54733));
                        return;
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreOpen));
                }
            }
            else 
            {
                GameManager.instance.popupView(GameController.petHire.view);
            }
            return;
        }

        public show(arg1: Boolean): void
        {
            this._menuSprite.visible = arg1;
            return;
        }

        public tween(): void
        {
            this._exploreBtn.y = 115;
            this._hireBtn.y = 115;
            TweenMax.to(this._exploreBtn, 0.1, {"y": 60});
            TweenMax.to(this._hireBtn, 0.2, {"y": 5});
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.show(true);
            this._container.addChild(this);
            return;
        }

        /* internal  */onMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.show(false);
            DisplayUtil.removeMe(this);
            return;
        }

        public guidePetFight(): void
        {
            EffectManager.glowFilterReg(this._competitionBtn, null, 1, 10, 0, 20);
            var loc1=GuideTipsManager.getGuideTips(GuideTipsManager.Dir_BR, Language.getString(20331));
            loc1.x = this._competitionBtn.x + 10;
            loc1.y = this._competitionBtn.y + 10;
            addChild(loc1);
            return;
        }

        public guidePetLifeStyle(): void
        {
            var loc1=null;
            EffectManager.glowFilterReg(this._juBtn, null, 1, 10, 0, 20);
            loc1 = GuideTipsManager.getGuideTips(GuideTipsManager.Dir_BR, Language.getString(27203));
            loc1.x = this._juBtn.x + 10;
            loc1.y = this._juBtn.y + 10;
            addChild(loc1);
            return;
        }

        public onGuidePetEquipRefresh(): void
        {
            var loc1=null;
            EffectManager.glowFilterReg(this._forgeBtn, null, 1, 10, 0, 20);
            loc1 = GuideTipsManager.getGuideTips(GuideTipsManager.Dir_BR, Language.getString(20332));
            loc1.x = this._forgeBtn.x + 10;
            loc1.y = this._forgeBtn.y + 10;
            addChild(loc1);
            return;
        }

        public onGuidePetEquipStrenthen(): void
        {
            var loc1=null;
            EffectManager.glowFilterReg(this._forgeBtn, null, 1, 10, 0, 20);
            loc1 = GuideTipsManager.getGuideTips(GuideTipsManager.Dir_BR, Language.getString(20334));
            loc1.x = this._forgeBtn.x + 10;
            loc1.y = this._forgeBtn.y + 10;
            addChild(loc1);
            return;
        }

        public get isGuideTips(): Boolean
        {
            if (GuideTipsManager.guideTips.parent == this) 
            {
                return true;
            }
            return false;
        }

        /* internal */ /* var */_menuSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_hireBtn: GLoadedButton;

        /* internal */ /* var */_exploreBtn: GLoadedButton;

        /* internal */ /* var */_forgeBtn: GLoadedButton;

        /* internal */ /* var */_competitionBtn: GLoadedButton;

        /* internal */ /* var */_juBtn: GLoadedButton;

        /* internal */ /* var */_container: Object /* flash.display.DisplayObjectContainer */;
    }
